package com.zxw.java基础.字符串;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @projectName: util-cloud
 * @package: com.zxw.java基础.字符串
 * @className: 下标捋顺
 * @author: zhangxuewei
 * @description:
 * @date: 2024/7/16 10:48
 * @version: 1.0
 */
public class 下标捋顺 {
    public static void main(String[] args) {
        String originalText = "<el-table-column type=\"selection\" width=\"55\" :align=\"'center'\" />\n" +
                "      <el-table-column v-if=\"columns[0].visible\" :show-overflow-tooltip=\"true\" label=\"财资流水号\" :align=\"'center'\" prop=\"billNo\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[1].visible\" :show-overflow-tooltip=\"true\" label=\"ERP批次流水号\" :align=\"'center'\" prop=\"apiBatchNo\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[2].visible\" :show-overflow-tooltip=\"true\" label=\"ERP单笔流水号\" :align=\"'center'\" prop=\"apiDtlNo\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[3].visible\" :show-overflow-tooltip=\"true\" label=\"票据类型\" :align=\"'center'\" prop=\"draftType\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <dict-tag :options=\"fi_cz_draft_type\" :value=\"scope.row.draftType\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[4].visible\" :show-overflow-tooltip=\"true\" label=\"票据类型名称\" :align=\"'center'\" prop=\"draftTypeName\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[5].visible\" :show-overflow-tooltip=\"true\" label=\"交易状态\" :align=\"'center'\" prop=\"transState\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <dict-tag :options=\"fi_cz_draft_trans_status\" :value=\"scope.row.transState\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[6].visible\" :show-overflow-tooltip=\"true\" label=\"交易状态信息\" :align=\"'center'\" prop=\"transStateShow\" min-width=\"106\" />\n" +
                "      <el-table-column v-if=\"columns[7].visible\" :show-overflow-tooltip=\"true\" label=\"交易信息\" :align=\"'center'\" prop=\"transInfo\" min-width=\"90\" />\n" +
                "      <el-table-column v-if=\"columns[58].visible\" :show-overflow-tooltip=\"true\" label=\"签收类型\" :align=\"'center'\" prop=\"transrespondFlag\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <dict-tag :options=\"nbcz_transrespond_flag\" :value=\"scope.row.transrespondFlag\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[8].visible\" :show-overflow-tooltip=\"true\" label=\"推送NC状态\" :align=\"'center'\" prop=\"pushNcStatus\" min-width=\"100\">\n" +
                "        <template #default=\"{ row }\">\n" +
                "          <dict-tag :options=\"fi_bs_push_nc_status\" :value=\"row.pushNcStatus\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[9].visible\" :show-overflow-tooltip=\"true\" label=\"收款分类\" :align=\"'center'\" prop=\"acceptancesIncomeType\" min-width=\"90\">\n" +
                "        <template #default=\"{ row }\">\n" +
                "          <dict-tag :options=\"fi_bill_income_type\" :value=\"row.acceptancesIncomeType\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[10].visible\" :show-overflow-tooltip=\"true\" label=\"单据状态\" :align=\"'center'\" prop=\"acceptancesConfirmStatus\" min-width=\"90\" >\n" +
                "        <template #default=\"scope\">\n" +
                "          <dict-tag :options=\"fi_accepetances_confirm_status\" :value=\"scope.row.acceptancesConfirmStatus\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[11].visible\" :show-overflow-tooltip=\"true\" label=\"票据编码\" :align=\"'center'\" prop=\"draftCode\" min-width=\"260\" />\n" +
                "      <el-table-column v-if=\"columns[12].visible\" :show-overflow-tooltip=\"true\" label=\"子票区间\" :align=\"'center'\" prop=\"childRange\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[13].visible\" :show-overflow-tooltip=\"true\" label=\"本次子票区间\" :align=\"'center'\" prop=\"newChildRange\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[14].visible\" :show-overflow-tooltip=\"true\" label=\"票据(包)金额\" :align=\"'right'\" prop=\"draftAmount\" min-width=\"150\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span style=\"color: #409eff;\">{{ NumFormat(scope.row.draftAmount) }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[15].visible\" :show-overflow-tooltip=\"true\" label=\"申请金额\" :align=\"'right'\" prop=\"operateMoney\" min-width=\"150\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span style=\"color: #409eff;\">{{ NumFormat(scope.row.operateMoney) }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[16].visible\" :show-overflow-tooltip=\"true\" label=\"开户名称\" :align=\"'center'\" prop=\"dmCustomerName\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[17].visible\" :show-overflow-tooltip=\"true\" label=\"销售人员名称\" :align=\"'center'\" prop=\"dmSalePsnName\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[18].visible\" :show-overflow-tooltip=\"true\" label=\"所属组织名称\" :align=\"'center'\" prop=\"dmOrgName\" min-width=\"200\" />\n" +
                "      <el-table-column v-if=\"columns[19].visible\" :show-overflow-tooltip=\"true\" label=\"所属部门名称\" :align=\"'center'\" prop=\"dmNcDeptName\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[20].visible\" :show-overflow-tooltip=\"true\" label=\"审核人名称\" :align=\"'center'\" prop=\"dmAuditorName\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[21].visible\" :show-overflow-tooltip=\"true\" label=\"审核人编码\" :align=\"'center'\" prop=\"dmAuditorCode\" min-width=\"150\" />\n" +
                "      <el-table-column v-if=\"columns[22].visible\" :show-overflow-tooltip=\"true\" label=\"审核时间\" :align=\"'center'\" prop=\"dmAuditTime\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[23].visible\" :show-overflow-tooltip=\"true\" label=\"出票日期\" :align=\"'center'\" prop=\"registerDate\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span>{{ parseTime(scope.row.registerDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[24].visible\" :show-overflow-tooltip=\"true\" label=\"到期日期\" :align=\"'center'\" prop=\"endDate\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[25].visible\" :show-overflow-tooltip=\"true\" label=\"转让标记\" :align=\"'center'\" prop=\"exchangeFlag\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[26].visible\" :show-overflow-tooltip=\"true\" label=\"转让标记展示\" :align=\"'center'\" prop=\"exchangeFlagShow\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[27].visible\" :show-overflow-tooltip=\"true\" label=\"出票人名称\" :align=\"'center'\" prop=\"drawerName\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[28].visible\" :show-overflow-tooltip=\"true\" label=\"出票人账号\" :align=\"'center'\" prop=\"drawerAccountNumber\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[29].visible\" :show-overflow-tooltip=\"true\" label=\"出票人开户行机构号\" :align=\"'center'\" prop=\"drawerBankBranchId\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[30].visible\" :show-overflow-tooltip=\"true\" label=\"出票人开户行机构名称\" :align=\"'center'\" prop=\"drawerBankBranchName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[31].visible\" :show-overflow-tooltip=\"true\" label=\"承兑人名称\" :align=\"'center'\" prop=\"acceptorName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[32].visible\" :show-overflow-tooltip=\"true\" label=\"承兑人账号\" :align=\"'center'\" prop=\"acceptorAccountNumber\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[33].visible\" :show-overflow-tooltip=\"true\" label=\"承兑人开户行机构号\" :align=\"'center'\" prop=\"acceptorBankBranchId\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[34].visible\" :show-overflow-tooltip=\"true\" label=\"承兑人开户行机构名称\" :align=\"'center'\" prop=\"acceptorBankBranchName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[35].visible\" :show-overflow-tooltip=\"true\" label=\"收款人名称\" :align=\"'center'\" prop=\"receiver\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[36].visible\" :show-overflow-tooltip=\"true\" label=\"收款人账号\" :align=\"'center'\" prop=\"receiverAccountNumber\" min-width=\"200\" />\n" +
                "      <el-table-column v-if=\"columns[37].visible\" :show-overflow-tooltip=\"true\" label=\"收款人开户行机构号\" :align=\"'center'\" prop=\"receiverBankBranchId\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[38].visible\" :show-overflow-tooltip=\"true\" label=\"收款人开户行机构名称\" :align=\"'center'\" prop=\"receiverBankBranchName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[39].visible\" :show-overflow-tooltip=\"true\" label=\"交易类型\" :align=\"'center'\" prop=\"operateFlag\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[40].visible\" :show-overflow-tooltip=\"true\" label=\"交易类型展示\" :align=\"'center'\" prop=\"operateFlagShow\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[41].visible\" :show-overflow-tooltip=\"true\" label=\"提交人\" :align=\"'center'\" prop=\"op\" />\n" +
                "      <el-table-column v-if=\"columns[42].visible\" :show-overflow-tooltip=\"true\" label=\"提交人名称\" :align=\"'center'\" prop=\"operName\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[43].visible\" :show-overflow-tooltip=\"true\" label=\"本方单位名称\" :align=\"'center'\" prop=\"corpName\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[44].visible\" :show-overflow-tooltip=\"true\" label=\"本方户名\" :align=\"'center'\" prop=\"accountName\" min-width=\"250\" />\n" +
                "      <el-table-column v-if=\"columns[45].visible\" :show-overflow-tooltip=\"true\" label=\"本方账号\" :align=\"'center'\" prop=\"accountNumber\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[46].visible\" :show-overflow-tooltip=\"true\" label=\"本方账户开户行机构代码\" :align=\"'center'\" prop=\"accountBankBranchId\" min-width=\"200\" />\n" +
                "      <el-table-column v-if=\"columns[47].visible\" :show-overflow-tooltip=\"true\" label=\"本方账户开户行机构名称\" :align=\"'center'\" prop=\"accountBankBranchName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[48].visible\" :show-overflow-tooltip=\"true\" label=\"对方账号\" :align=\"'center'\" prop=\"recAccountNumber\" min-width=\"200\" />\n" +
                "      <el-table-column v-if=\"columns[49].visible\" :show-overflow-tooltip=\"true\" label=\"对方名称\" :align=\"'center'\" prop=\"recName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[50].visible\" :show-overflow-tooltip=\"true\" label=\"对方账户开户行机构代码\" :align=\"'center'\" prop=\"recBankBranchId\" min-width=\"200\" />\n" +
                "      <el-table-column v-if=\"columns[51].visible\" :show-overflow-tooltip=\"true\" label=\"对方账户开户行机构名称\" :align=\"'center'\" prop=\"recBankBranchName\" min-width=\"350\" />\n" +
                "      <el-table-column v-if=\"columns[52].visible\" :show-overflow-tooltip=\"true\" label=\"操作日期\" :align=\"'center'\" prop=\"operateDate\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span>{{ parseTime(scope.row.operateDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[53].visible\" :show-overflow-tooltip=\"true\" label=\"批次号\" :align=\"'center'\" prop=\"batchNo\" min-width=\"200\" />\n" +
                "      <el-table-column v-if=\"columns[54].visible\" :show-overflow-tooltip=\"true\" label=\"是否自动提示收票\" :align=\"'center'\" prop=\"isAutoRecvDraft\" min-width=\"156\" />\n" +
                "      <el-table-column v-if=\"columns[55].visible\" :show-overflow-tooltip=\"true\" label=\"追索类型\" :align=\"'center'\" prop=\"recourseType\" />\n" +
                "      <el-table-column v-if=\"columns[56].visible\" :show-overflow-tooltip=\"true\" label=\"贴现利率\" :align=\"'center'\" prop=\"discountRate\" />\n" +
                "      <el-table-column v-if=\"columns[57].visible\" :show-overflow-tooltip=\"true\" label=\"实付金额\" :align=\"'right'\" prop=\"discountAmount\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span style=\"color: #409eff;\">{{ NumFormat(scope.row.discountAmount) }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[59].visible\" :show-overflow-tooltip=\"true\" label=\"业务发起方式\" :align=\"'center'\" prop=\"businessType\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <dict-tag :options=\"nbcz_business_type\" :value=\"scope.row.businessType\" />\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[60].visible\" :show-overflow-tooltip=\"true\" label=\"出票方式\" :align=\"'center'\" prop=\"drawerModel\" />\n" +
                "      <el-table-column v-if=\"columns[61].visible\" :show-overflow-tooltip=\"true\" label=\"创建者ID\" :align=\"'center'\" prop=\"createById\" />\n" +
                "      <el-table-column v-if=\"columns[62].visible\" :show-overflow-tooltip=\"true\" label=\"更新者ID\" :align=\"'center'\" prop=\"updateById\" />\n" +
                "      <el-table-column v-if=\"columns[63].visible\" :show-overflow-tooltip=\"true\" label=\"数据更新时间\" :align=\"'center'\" prop=\"ts\" min-width=\"156\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <span>{{ parseTime(scope.row.ts, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>\n" +
                "        </template>\n" +
                "      </el-table-column>\n" +
                "      <el-table-column v-if=\"columns[64].visible\" label=\"数据版本\" :align=\"'center'\" prop=\"version\" />\n" +
                "      <el-table-column v-if=\"columns[65].visible\" label=\"操作\" fixed=\"right\" :align=\"'center'\" min-width=\"185\">\n" +
                "        <template #default=\"scope\">\n" +
                "          <el-button link type=\"primary\" v-hasPermi=\"['fi:acceptancesTransInfo:query']\" @click=\"handleView(scope.row)\">查看</el-button>\n" +
                "          <el-button v-if=\"scope.row.acceptancesConfirmStatus==null || scope.row.acceptancesConfirmStatus==0\" link type=\"primary\" v-hasPermi=\"['fi:acceptancesTransInfo:edit']\" @click=\"handleEdit(scope.row)\">编辑</el-button>\n" +
                "          <el-button v-if=\"scope.row.acceptancesConfirmStatus==0\" link type=\"primary\" v-hasPermi=\"['fi:acceptancesTransInfo:passAudit']\" @click=\"handleAudit(scope.row)\">审核</el-button>\n" +
                "          <el-button v-if=\"scope.row.acceptancesConfirmStatus==1\" link type=\"primary\" v-hasPermi=\"['fi:acceptancesTransInfo:cancelAudit']\" @click=\"handleCancelAudit(scope.row)\">取消审核</el-button>\n" +
                "        </template>\n" +
                "      </el-table-column>";

        List<String> columnProps = extractColumnProps(originalText);

        int startIndex = 0; // 初始下标值

        StringBuilder modifiedText = new StringBuilder();

        String[] lines = originalText.split("\n");

        for (String prop : columnProps) {
            int index = startIndex++;
            String updatedLine = findAndReplaceIndex(lines, prop, index);
            modifiedText.append(updatedLine).append("\n");
        }

        System.out.println(modifiedText.toString());
    }

    private static List<String> extractColumnProps(String originalText) {
        List<String> columnProps = new ArrayList<>();
        Pattern pattern = Pattern.compile("prop=\"(.*?)\"");
        Matcher matcher = pattern.matcher(originalText);
        while (matcher.find()) {
            columnProps.add(matcher.group(1));
        }
        return columnProps;
    }

    private static String findAndReplaceIndex(String[] lines, String prop, int index) {
        for (String line : lines) {
            if (line.contains("prop=\"" + prop + "\"")) {
                return line.replaceAll("columns\\[\\d+\\]", "columns[" + index + "]");
            }
        }
        return null;
    }
}
